﻿#include <QMessageBox>
#include "CPanItemConfig.h"
#include "CHeader.h"
#include "CPresetAreaSetDialog.h"
#include "CLogOper.h"

CPanItemConfig::CPanItemConfig(QString sSceneGuid, QString sPointGuid, CDevBase* pDev,CPolArea* pPolArea,CRBaseData* pBasicData, QWidget *parent)
	: m_sGuid(sSceneGuid),m_sPointGuid(sPointGuid),m_pDev(pDev),m_pPolAreaOld(pPolArea),m_pBasicData(pBasicData),QWidget(parent)
{
	ui.setupUi(this);
	m_nMax = 0;
	initConnect();
	initData();
}

CPanItemConfig::~CPanItemConfig()
{}

void CPanItemConfig::initData()
{
	ui.labelItemGuid->hide();
	ui.lineEditItemGuid->hide();
	ui.comboBoxDevTypeCode->addItem(A2T("图像相机"));
	ui.comboBoxDevTypeCode->addItem(A2T("红外相机"));
	ui.comboBoxDevTypeCode->addItem(A2T("声音传感器"));
	m_mapDevTypeCode.insert(enCamer, A2T("图像相机"));
	m_mapDevTypeCode.insert(enIR, A2T("红外相机"));
	m_mapDevTypeCode.insert(enVoice, A2T("声音传感器"));

	ui.comboBoxTackPicture->addItem(A2T("是"));
	ui.comboBoxTackPicture->addItem(A2T("否"));

	ui.comboBoxAlarmLevel->addItem(A2T("一级"));
	ui.comboBoxAlarmLevel->addItem(A2T("二级"));
	ui.comboBoxAlarmLevel->addItem(A2T("三级"));
	m_mapAlarmType.insert(1, A2T("一级"));
	m_mapAlarmType.insert(2, A2T("二级"));
	m_mapAlarmType.insert(3, A2T("三级"));

	ui.comboBoxCheckType->addItem(A2T("调用返回"));
	ui.comboBoxCheckType->addItem(A2T("持续任务主动上报"));
	m_mapCheckType.insert(0, A2T("调用返回"));
	m_mapCheckType.insert(1, A2T("持续任务主动上报"));
	m_mapDataType = m_pBasicData->m_mapItemData;
	QVector<QString> vecDataTypeName = m_mapDataType.values().toVector();
	ui.comboBoxDataType->addItems(vecDataTypeName.toList());
	
	ui.comboBoxCollectIndex->addItem(A2T("起点"));
	ui.comboBoxCollectIndex->addItem(A2T("终点"));
	ui.comboBoxCollectIndex->addItem(A2T("中间点"));
	m_mapCollectIndex.insert(0, A2T("起点"));
	m_mapCollectIndex.insert(1, A2T("终点"));
	m_mapCollectIndex.insert(2, A2T("中间点"));

	m_mapBelong.insert(0, A2T("A侧-上托辊"));
	m_mapBelong.insert(1, A2T("A侧-下托辊"));
	m_mapBelong.insert(2, A2T("B侧-上托辊"));
	m_mapBelong.insert(3, A2T("B侧-下托辊"));
	m_mapBelong.insert(4, A2T("C侧-上托辊"));
	m_mapBelong.insert(5, A2T("C侧-下托辊"));
	ui.comboBoxBelong->addItem(A2T("A侧-上托辊"));
	ui.comboBoxBelong->addItem(A2T("A侧-下托辊"));
	ui.comboBoxBelong->addItem(A2T("B侧-上托辊"));
	ui.comboBoxBelong->addItem(A2T("B侧-下托辊"));
	ui.comboBoxBelong->addItem(A2T("C侧-上托辊"));
	ui.comboBoxBelong->addItem(A2T("C侧-下托辊"));
	m_mapCollectCheckType.insert(0, A2T("根据米数判断"));
	m_mapCollectCheckType.insert(1, A2T("根据托辊个数判断"));
	//ui.comboBoxCollectCheckType->addItem(A2T("根据米数判断"));
	ui.comboBoxCollectCheckType->addItem(A2T("根据托辊个数判断"));

	ui.comboBoxIsExecAI->addItem(A2T("否"));
	ui.comboBoxIsExecAI->addItem(A2T("是"));

	//获取最大的相机预置点
	for (QMap<QString, CPolPoint*>::iterator itorPoint = m_pPolAreaOld->m_mapPolPoint.begin(); itorPoint != m_pPolAreaOld->m_mapPolPoint.end(); itorPoint++)
	{
		CPolPoint* pPoint = itorPoint.value();
		for (QMap<QString, CPolItem*>::iterator itor = pPoint->m_mapPolItem.begin();
			itor != pPoint->m_mapPolItem.end(); itor++)
		{
			if (itor.value()->m_nDevType == 1)
			{
				CPolItemCamer* pCPolItem = (CPolItemCamer*)itor.value();
				if (pCPolItem->m_dAngelCamer > m_nMax)
				{
					m_nMax = pCPolItem->m_dAngelCamer;
				}
			}
		}
	}
	
	m_nMax++;
	for (int i = 1; i <= m_nMax; i++)
	{
		ui.comboBoxPersetNo->addItem(QString::number(i));
	}
	//ui.lineEditPersetNo->setText(QString::number(m_nMax));
	ui.lineEditPersetNo->setText(QString::number(1));//默认1号预置点 wxy++20240526

	ui.comboBoxIsShwoPdf->addItem(A2T("是"));
	ui.comboBoxIsShwoPdf->addItem(A2T("否"));
}

void CPanItemConfig::initConnect()
{
	connect(ui.pushButtonSave, &QPushButton::clicked, this, &CPanItemConfig::slotPushButtonSaveClicked);
	connect(ui.comboBoxDevTypeCode, SIGNAL(currentIndexChanged(int)), this, SLOT(slotDevTypeCodeChanged(int)));
	connect(ui.comboBoxCheckType, SIGNAL(currentIndexChanged(int)), this, SLOT(slotCheckTypeChanged(int)));
	connect(ui.comboBoxCollectCheckType, SIGNAL(currentIndexChanged(int)), this, SLOT(slotCollectCheckTypeChanged(int)));
	connect(ui.comboBoxIsExecAI, SIGNAL(currentIndexChanged(int)), this, SLOT(slotIsExecAIChanged(int)));
	connect(ui.pushButtonAreaSet, &QPushButton::clicked, this, &CPanItemConfig::slotPrestAreaSet);
	connect(ui.pushButtonGoToPersetNo, &QPushButton::clicked, this, &CPanItemConfig::slotGoToPrestNo);
	connect(ui.pushButton_Alarm, &QPushButton::clicked, this, &CPanItemConfig::slotAlarmSet);
}

//判断是否是云台系统的固定不可用点 wxy++20240527
bool CPanItemConfig::judgeYtSysPoint(int nPresetPointNumber)
{
	if (nPresetPointNumber == 34 || nPresetPointNumber == 35 || nPresetPointNumber == 36
		|| nPresetPointNumber == 37 || nPresetPointNumber == 38 || nPresetPointNumber == 39
		|| nPresetPointNumber == 40 || nPresetPointNumber == 45 || nPresetPointNumber == 46
		|| nPresetPointNumber == 47 || nPresetPointNumber == 92 || nPresetPointNumber == 93 || nPresetPointNumber == 94 || nPresetPointNumber == 95
		|| nPresetPointNumber == 96 || nPresetPointNumber == 97 || nPresetPointNumber == 98
		|| nPresetPointNumber == 99 || nPresetPointNumber == 100 || nPresetPointNumber == 101
		|| nPresetPointNumber == 102 || nPresetPointNumber == 103 || nPresetPointNumber == 104
		|| nPresetPointNumber == 105 || nPresetPointNumber < 1 || nPresetPointNumber > 255)//超过255PLC会数字溢出
	{
		return false;
	}
	else
	{
		return true;
	}
}

void CPanItemConfig::slotPushButtonSaveClicked()
{
	int nRet = messageBox(3,A2T("是否确认此操作"));
	if (nRet == QMessageBox::No || QMessageBox::Close == nRet)
	{
		return;
	}
	if (m_nType == 0)//增加
	{
		//判断是否填写完整
		if (ui.lineEditItemName->text() == "" || ui.lineEditItemZ->text() == "" || ui.lineEditCollectTime->text() == "")
		{
			messageBox(0, A2T("请填写完整后再进行操作"));
			return;
		}
		QString sGuid = createGuid();
		CPolItemCamer* pItem = new CPolItemCamer();
		pItem->m_sItemGuid = sGuid;
		pItem->m_sPointGuid = m_sPointGuid;
		pItem->m_sGuid = m_sGuid;
		pItem->m_sItemName = ui.lineEditItemName->text();
		pItem->m_nDevTypeCode = m_mapDevTypeCode.key(ui.comboBoxDevTypeCode->currentText());
		pItem->m_nCheckType = m_mapCheckType.key(ui.comboBoxCheckType->currentText());
		pItem->m_nCollectIndex = m_mapCollectIndex.key(ui.comboBoxCollectIndex->currentText());
		pItem->m_nDevType = 1;//云台巡检项
		if (ui.comboBoxTackPicture->currentText() == A2T("是"))
		{
			pItem->m_nTackPicture = 1;
		}
		else if (ui.comboBoxTackPicture->currentText() == A2T("否"))
		{
			pItem->m_nTackPicture = 0;
		}
		pItem->m_nDataType = m_mapDataType.key(ui.comboBoxDataType->currentText());
		pItem->m_dItemZ = ui.lineEditItemZ->text().toDouble();//巡检项坐标Z(现在是cm)
		pItem->m_dCollectTime = ui.lineEditCollectTime->text().toDouble();
		pItem->m_nAlarmLevel = m_mapAlarmType.key(ui.comboBoxAlarmLevel->currentText());
		pItem->m_sDataThreadHoldH = ui.lineEditDataThreadHoldH->text();
		pItem->m_sDataThreadHoldHH = ui.lineEditDataThreadHoldHH->text();
		pItem->m_sDataThreadHoldL = ui.lineEditDataThreadHoldL->text();
		pItem->m_sDataThreadHoldLL = ui.lineEditDataThreadHoldLL->text();
		pItem->m_dAngelCamer = ui.lineEditPersetNo->text().toInt();
		pItem->m_nItemStatus = 1;//新增巡检项
		pItem->m_nIndex = m_pPolAreaOld->m_mapPolPoint[m_sPointGuid]->getItemMaxIndex() + 1;
		pItem->m_nCollectCheckType = m_mapCollectCheckType.key(ui.comboBoxCollectCheckType->currentText());
		if (pItem->m_nCollectCheckType == 0)
		{
			pItem->m_dCollectInterval = ui.lineEditCollectInterval->text().toDouble();
			pItem->m_nCollectRollerNum = 0;
		}
		else
		{
			pItem->m_nCollectRollerNum = ui.lineEditCollectInterval->text().toInt();
			pItem->m_dCollectInterval = 0;
		}
		pItem->m_nBelong= m_mapBelong.key(ui.comboBoxBelong->currentText());
		pItem->m_dRollerOffdetDis = ui.lineEditRollerOffsetDis->text().toDouble();
		if (ui.comboBoxIsExecAI->currentText() == A2T("是"))
		{
			pItem->m_nIsExecAI = 1;
		}
		else
		{
			pItem->m_nIsExecAI = 0;
		}
		if (ui.comboBoxIsShwoPdf->currentText() == A2T("是"))
		{
			pItem->m_nIsShowPdf = 1;
		}
		else
		{
			pItem->m_nIsShowPdf = 0;
		}
		m_pPolAreaOld->m_mapPolPoint[m_sPointGuid]->m_mapPolItem.insert(sGuid, pItem);
		if (m_pPolAreaOld->m_mapPolPoint[m_sPointGuid]->m_nPointStatus == 0)
		{
			m_pPolAreaOld->m_mapPolPoint[m_sPointGuid]->m_nPointStatus = 2;
		}
		else if(m_pPolAreaOld->m_mapPolPoint[m_sPointGuid]->m_nPointStatus == 1)
		{
			m_pPolAreaOld->m_mapPolPoint[m_sPointGuid]->m_nPointStatus = 1;
		}
		else if (m_pPolAreaOld->m_mapPolPoint[m_sPointGuid]->m_nPointStatus == 2)
		{
			m_pPolAreaOld->m_mapPolPoint[m_sPointGuid]->m_nPointStatus = 2;
		}
		//通知添加成功
		messageBox(0, A2T("添加成功"));
		/*SExecLog sLog;
		sLog.m_dLogTime = QDateTime::currentDateTime();
		sLog.m_nAlarmLevel = enWorkInfo;
		sLog.m_sDescriptionl = A2T("%1添加了%2名为%3的云台巡检项")
			.arg(CPublicData::instance().m_userInfo.sUserName)
			.arg(CPublicData::instance().m_mapIFScene[m_sGuid]->m_sSceneName.get())
			.arg(ui.lineEditItemName->text());
		sLog.m_sDevName = A2T("巡检项");
		CLogOper::instance().addMsg(m_sGuid, sLog);*/
		//通知上层刷新界面
		emit(sigRefushUI());
		this->close();
	}
	else if (m_nType == 1)//修改
	{
		//判断是否填写完整
		if (ui.lineEditItemName->text() == "" || ui.lineEditItemZ->text() == "" || ui.lineEditCollectTime->text() == "")
		{
			messageBox(0, A2T("请填写完整后再进行操作"));
			return;
		}
		CPolItemCamer* pItem = (CPolItemCamer*)m_pPolAreaOld->m_mapPolPoint[m_sPointGuid]->m_mapPolItem[ui.lineEditItemGuid->text()];
		pItem->m_sItemGuid = ui.lineEditItemGuid->text();
		pItem->m_sItemName = ui.lineEditItemName->text();
		pItem->m_nDevTypeCode = m_mapDevTypeCode.key(ui.comboBoxDevTypeCode->currentText());
		pItem->m_nCheckType = m_mapCheckType.key(ui.comboBoxCheckType->currentText());
		pItem->m_nCollectIndex = m_mapCollectIndex.key(ui.comboBoxCollectIndex->currentText());
		if (ui.comboBoxTackPicture->currentText() == A2T("是"))
		{
			pItem->m_nTackPicture = 1;
		}
		else if (ui.comboBoxTackPicture->currentText() == A2T("否"))
		{
			pItem->m_nTackPicture = 0;
		}
		pItem->m_nDataType = m_mapDataType.key(ui.comboBoxDataType->currentText());
		pItem->m_dItemZ = ui.lineEditItemZ->text().toDouble();//巡检项坐标Z(现在是cm)
		pItem->m_dCollectTime = ui.lineEditCollectTime->text().toDouble();
		pItem->m_nAlarmLevel = m_mapAlarmType.key(ui.comboBoxAlarmLevel->currentText());
		pItem->m_sDataThreadHoldH = ui.lineEditDataThreadHoldH->text();
		pItem->m_sDataThreadHoldHH = ui.lineEditDataThreadHoldHH->text();
		pItem->m_sDataThreadHoldL = ui.lineEditDataThreadHoldL->text();
		pItem->m_sDataThreadHoldLL = ui.lineEditDataThreadHoldLL->text();
		pItem->m_dAngelCamer = ui.lineEditPersetNo->text().toInt();
		pItem->m_nCollectCheckType = m_mapCollectCheckType.key(ui.comboBoxCollectCheckType->currentText());
		if (pItem->m_nCollectCheckType == 0)
		{
			pItem->m_dCollectInterval = ui.lineEditCollectInterval->text().toDouble();
		}
		else
		{
			pItem->m_nCollectRollerNum = ui.lineEditCollectInterval->text().toInt();
		}
		pItem->m_nBelong = m_mapBelong.key(ui.comboBoxBelong->currentText());
		pItem->m_dRollerOffdetDis = ui.lineEditRollerOffsetDis->text().toDouble();
		if (ui.comboBoxIsExecAI->currentText() == A2T("是"))
		{
			pItem->m_nIsExecAI = 1;
		}
		else
		{
			pItem->m_nIsExecAI = 0;
		}
		if (ui.comboBoxIsShwoPdf->currentText() == A2T("是"))
		{
			pItem->m_nIsShowPdf = 1;
		}
		else
		{
			pItem->m_nIsShowPdf = 0;
		}
		if (pItem->m_nItemStatus != 1)
		{
			pItem->m_nItemStatus = 2;
		}
		
		if (m_pPolAreaOld->m_mapPolPoint[m_sPointGuid]->m_nPointStatus == 0)
		{
			m_pPolAreaOld->m_mapPolPoint[m_sPointGuid]->m_nPointStatus = 2;
		}
		else if (m_pPolAreaOld->m_mapPolPoint[m_sPointGuid]->m_nPointStatus == 1)
		{
			m_pPolAreaOld->m_mapPolPoint[m_sPointGuid]->m_nPointStatus = 1;
		}
		else if (m_pPolAreaOld->m_mapPolPoint[m_sPointGuid]->m_nPointStatus == 2)
		{
			m_pPolAreaOld->m_mapPolPoint[m_sPointGuid]->m_nPointStatus = 2;
		}
		//通知添加成功
		messageBox(0, A2T("修改成功"));
		/*SExecLog sLog;
		sLog.m_dLogTime = QDateTime::currentDateTime();
		sLog.m_nAlarmLevel = enWorkInfo;
		sLog.m_sDescriptionl = A2T("%1修改了%2名为%3的云台巡检项")
			.arg(CPublicData::instance().m_userInfo.sUserName)
			.arg(CPublicData::instance().m_mapIFScene[m_sGuid]->m_sSceneName.get())
			.arg(ui.lineEditItemName->text());
		sLog.m_sDevName = A2T("巡检项");
		CLogOper::instance().addMsg(m_sGuid, sLog);*/
		//通知上层刷新界面
		emit(sigRefushUI());
		this->close();
	}
	return;
}

void CPanItemConfig::slotGetRobZ()
{
	CDevDataBase* pDevData = (CDevDataBase*)m_pDev->m_pDevDataBase;
	double dRobZLoca = pDevData->m_sRobCurrLocaZ.toDouble() / 10;//显示cm
	ui.lineEditItemZ->setText(QString::number(dRobZLoca));
}

//设置相机预置点
void CPanItemConfig::slotSetPanPreset()
{
	SCtrInfo info;
	info.m_sGuid = m_sGuid;
	info.m_bCtrSync = true;
	info.m_nCtrDevType = enSubDev1;
	info.m_nCtrCmd = enCSetPointCamer;
	//info.m_nCamerAngle = m_nMax;
	//需要把当前输入的预置点设置进去 wxy++20240526
	int nPreinstallPoint = ui.lineEditPersetNo->text().toInt();
	info.m_nCamerAngle = nPreinstallPoint;

	if (!judgeYtSysPoint(info.m_nCamerAngle))
	{
		messageBox(2, A2T("当前预设点号[%1]是系统固定点 或者 不在1~255之间的整数,请重新输入一个重试").arg(info.m_nCamerAngle));
		return;
	}


	bool bRet=m_pDev->ctrDev(info);
	if (bRet == true)
	{
		messageBox(0, A2T("设置相机预置点%1成功").arg(info.m_nCamerAngle));
	}
	else
	{
		messageBox(2, A2T("设置相机预置点%1失败").arg(info.m_nCamerAngle));
	}
}

void CPanItemConfig::slotDevTypeCodeChanged(int nIndex)
{
	if (ui.comboBoxDevTypeCode->currentText() == A2T("图像相机"))
	{
		ui.labelDataThreadHoldH->hide();
		ui.labelDataThreadHoldHH->hide();
		ui.labelDataThreadHoldL->hide();
		ui.labelDataThreadHoldLL->hide();
		ui.lineEditDataThreadHoldHH->hide();
		ui.lineEditDataThreadHoldH->hide();
		ui.lineEditDataThreadHoldLL->hide();
		ui.lineEditDataThreadHoldL->hide();
		ui.lineEditItemName->setText(A2T("图像相机巡检项"));
		ui.comboBoxDataType->clear();
		for (QMap<int, QString>::iterator itor = m_mapDataType.begin(); itor != m_mapDataType.end(); itor++)
		{
			QString sName = itor.value();
			if (sName == A2T("红外测温"))
			{
				continue;
			}
			else
			{
				ui.comboBoxDataType->addItem(sName);
			}
		}
	}
	else if (ui.comboBoxDevTypeCode->currentText() == A2T("红外相机"))
	{
		ui.labelDataThreadHoldH->show();
		ui.labelDataThreadHoldH->setText(A2T("温度报警上限(℃):"));
		ui.labelDataThreadHoldHH->show();
		ui.labelDataThreadHoldHH->setText(A2T("温度报警上上限(℃):"));
		ui.labelDataThreadHoldL->hide();
		ui.labelDataThreadHoldL->setText(A2T("温度报警下限(℃):"));
		ui.labelDataThreadHoldLL->hide();
		ui.labelDataThreadHoldLL->setText(A2T("温度报警下下限(℃):"));
		ui.lineEditDataThreadHoldHH->show();
		ui.lineEditDataThreadHoldHH->setText(A2T("90"));
		ui.lineEditDataThreadHoldH->show();
		ui.lineEditDataThreadHoldH->setText(A2T("80"));
		ui.lineEditDataThreadHoldLL->hide();
		ui.lineEditDataThreadHoldLL->setText(A2T("-9999"));
		ui.lineEditDataThreadHoldL->hide();
		ui.lineEditDataThreadHoldL->setText(A2T("-9999"));
		ui.lineEditItemName->setText(A2T("红外相机巡检项"));
		ui.comboBoxDataType->clear();
		ui.comboBoxDataType->addItem(A2T("红外测温"));
	}
	else if (ui.comboBoxDevTypeCode->currentText() == A2T("声音传感器"))
	{
		ui.labelDataThreadHoldH->show();
		ui.labelDataThreadHoldH->setText(A2T("分贝值报警上限(db):"));
		ui.labelDataThreadHoldHH->show();
		ui.labelDataThreadHoldHH->setText(A2T("分贝值报警上上限(db):"));
		ui.labelDataThreadHoldL->hide();
		ui.labelDataThreadHoldL->setText(A2T("分贝值报警下限(db):"));
		ui.labelDataThreadHoldLL->hide();
		ui.labelDataThreadHoldLL->setText(A2T("分贝值报警下下限(db):"));
		ui.lineEditDataThreadHoldHH->show();
		ui.lineEditDataThreadHoldHH->setText(A2T("130"));
		ui.lineEditDataThreadHoldH->show();
		ui.lineEditDataThreadHoldH->setText(A2T("120"));
		ui.lineEditDataThreadHoldLL->hide();
		ui.lineEditDataThreadHoldLL->setText(A2T("-9999"));
		ui.lineEditDataThreadHoldL->hide();
		ui.lineEditDataThreadHoldL->setText(A2T("-9999"));
		ui.lineEditItemName->setText(A2T("声音传感器巡检项"));
		ui.comboBoxDataType->hide();
		ui.labelDataType->hide();
	}
}

void CPanItemConfig::slotCheckTypeChanged(int nIndex)
{
	if (ui.comboBoxCheckType->currentText() == A2T("调用返回"))
	{
		ui.lineEditCollectTime->show();
		ui.labelCollectTime->show();
		ui.labelItemZ->show();
		ui.lineEditItemZ->show();
		ui.labelPersetNo->show();
		ui.lineEditPersetNo->show();
		ui.comboBoxPersetNo->hide();//wxy++20240526
		ui.labelCollectIndex->hide();
		ui.comboBoxCollectIndex->hide();
		ui.labelCollectInterval->hide();
		ui.lineEditCollectInterval->hide();
		ui.labelCollectCheckType->hide();
		ui.comboBoxCollectCheckType->hide();
	}
	else if (ui.comboBoxCheckType->currentText() == A2T("持续任务主动上报"))
	{
		ui.lineEditCollectTime->show();
		ui.labelCollectTime->show();
		ui.labelItemZ->show();
		ui.lineEditItemZ->show();
		ui.labelPersetNo->show();//wxy++现场需求预置点需开放
		ui.lineEditPersetNo->show();//wxy++现场需求预置点需开放
		ui.comboBoxPersetNo->hide();
		ui.labelCollectIndex->show();
		ui.comboBoxCollectIndex->show();
		ui.labelCollectInterval->show();
		ui.lineEditCollectInterval->show();
		ui.labelCollectCheckType->show();
		ui.comboBoxCollectCheckType->show();
	}
	
}

void CPanItemConfig::slotCollectCheckTypeChanged(int nIndex)
{
	if (ui.comboBoxCollectCheckType->currentText() == A2T("根据米数判断"))
	{
		ui.labelCollectInterval->setText(A2T("持续监测报警间隔距离(m):"));
		ui.lineEditCollectInterval->setText(QString::number(2));
	}
	else if (ui.comboBoxCollectCheckType->currentText() == A2T("根据托辊个数判断"))
	{
		ui.labelCollectInterval->setText(A2T("持续监测报警间隔托辊个数:"));
		ui.lineEditCollectInterval->setText(QString::number(1));
	}
}

void CPanItemConfig::slotIsExecAIChanged(int nIndex)
{
	if (ui.comboBoxIsExecAI->currentText() == A2T("是"))
	{
		ui.labelDataType->show();
		ui.comboBoxDataType->show();
	}
	else if (ui.comboBoxIsExecAI->currentText() == A2T("否"))
	{
		ui.labelDataType->hide();
		ui.comboBoxDataType->hide();
	}
}

//设置预置点区域
void CPanItemConfig::slotPrestAreaSet()
{
	int nPresetNo = ui.lineEditPersetNo->text().toInt();
	CPresetAreaSetDialog uPresetAreaSetDlg(this);
	CDevDataCam* pCamData = ((CDevDataBase*)m_pDev->m_pDevDataBase)->m_pDevDataCam;
	uPresetAreaSetDlg.setCamearData(m_sGuid, nPresetNo, m_pDev, pCamData);
	uPresetAreaSetDlg.exec();
}

//运动到预置点
void CPanItemConfig::slotGoToPrestNo()
{
	int nPrestNo = ui.lineEditPersetNo->text().toInt();
	
	if (!judgeYtSysPoint(nPrestNo))
	{
		messageBox(2, A2T("当前预设点号[%1]是系统固定点 或者 不在1~255之间的整数,请重新输入一个重试").arg(nPrestNo));
		return;
	}

	//执行运动到预置点
	SCtrInfo info;
	info.m_sGuid = m_sGuid;
	info.m_bCtrSync = false;
	info.m_nCtrDevType = enSubDev1;
	info.m_nCtrCmd = enRunToPrestNo;
	info.m_nCamerAngle = nPrestNo;

	bool bRet = m_pDev->ctrDev(info);
	
}

void CPanItemConfig::slotAlarmSet()
{
	//ShowDetecStateBind(m_pDev->m_sDevGuid, ui.lineEditItemGuid->text(), 0);
}

void CPanItemConfig::setData(QString sGuid, QString sItemName, int nAlarmLevel, int nDevTypeCode, int nTackPicture,
	int nCheckType, int nDataType, int nCollectIndex, double dDataThreadHoldHH, double dDataThreadHoldLL, double dDataThreadHoldH,
	double dDataThreadHoldL, double dItemZ, double dCollectTime,int nPersetNo, double dCollectInterval,int nBelong, int nCollectCheckType, int nCollectRollerNum, double dRollerOffsetDis, int nIsExecAI,int nIsShowPdf)
{
	ui.lineEditItemGuid->setText(sGuid);
	ui.comboBoxAlarmLevel->setCurrentText(m_mapAlarmType.value(nAlarmLevel));
	if (nTackPicture == 1)
	{
		ui.comboBoxTackPicture->setCurrentText(A2T("是"));
	}
	else if (nTackPicture == 0)
	{
		ui.comboBoxTackPicture->setCurrentText(A2T("否"));
	}
	ui.comboBoxDevTypeCode->setCurrentText(m_mapDevTypeCode.value(nDevTypeCode));
	ui.comboBoxCheckType->setCurrentText(m_mapCheckType.value(nCheckType));
	ui.comboBoxDataType->setCurrentText(m_mapDataType.value(nDataType));
	ui.comboBoxCollectIndex->setCurrentText(m_mapCollectIndex.value(nCollectIndex));
	ui.lineEditDataThreadHoldHH->setText(QString::number(dDataThreadHoldHH));
	ui.lineEditDataThreadHoldLL->setText(QString::number(dDataThreadHoldLL));
	ui.lineEditDataThreadHoldH->setText(QString::number(dDataThreadHoldH));
	ui.lineEditDataThreadHoldL->setText(QString::number(dDataThreadHoldL));
	ui.lineEditItemZ->setText(QString::number(dItemZ));
	ui.lineEditCollectTime->setText(QString::number(dCollectTime));
	ui.lineEditPersetNo->setText(QString::number(nPersetNo));
	ui.lineEditItemName->setText(sItemName);//wxy++
	ui.comboBoxBelong->setCurrentText(m_mapBelong.value(nBelong));
	if (nCollectCheckType == 0)
	{
		ui.comboBoxCollectCheckType->setCurrentText(A2T("根据米数判断"));
		ui.lineEditCollectInterval->setText(QString::number(dCollectInterval));
	}
	else if (nCollectCheckType == 1)
	{
		ui.comboBoxCollectCheckType->setCurrentText(A2T("根据托辊个数判断"));
		ui.lineEditCollectInterval->setText(QString::number(nCollectRollerNum));
	}
	ui.lineEditRollerOffsetDis->setText(QString::number(dRollerOffsetDis));
	if (nIsExecAI == 0)
	{
		ui.comboBoxIsExecAI->setCurrentText(A2T("否"));
	}
	else
	{
		ui.comboBoxIsExecAI->setCurrentText(A2T("是"));
	}
	if (nIsShowPdf == 0)
	{
		ui.comboBoxIsShwoPdf->setCurrentText(A2T("否"));
	}
	else
	{
		ui.comboBoxIsShwoPdf->setCurrentText(A2T("是"));
	}
}

//设置标题
void CPanItemConfig::setTitle()
{
	if (m_nType == 0)
	{
		ui.label->setText(A2T("增加云台巡检项"));
	}
	else if(m_nType == 1)
	{
		ui.label->setText(A2T("修改云台巡检项"));
	}
}
